<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>组件的创建挂载顺序</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <div>
      <h2>{{ message }}</h2>
      <parent />
    </div>
  </div>
</body>
<script>
  new Vue({
    el: '#app',
    data: {
      message: 'hello world'
    },
    components: {
      parent: {
        name: 'parent',
        template: '<div>parent: <child /></div>',
        created() {
          console.log('parent created');
        },
        mounted() {
          console.log('parent mounted');
        },
        components: {
          child: {
            name: 'child',
            template: '<div>child</div>',
            created() {
              console.log('child created');
            },
            mounted() {
              console.log('child mounted');
            }
          }
        }
      }
    },
    beforeCreate() {
      console.log('root beforeCreate');
    },
    created() {
      console.log('root created');
    },
    beforeMount() {
      console.log('root beforeMount');
    },
    mounted() {
      console.log('root mounted')
    },
    beforeUpdate() {
      console.log('root beforeUpdate');
    },
    updated() {
      console.log('root update');
    },
    beforeDestroyed() {
      console.log('root beforeDestroyed');
    },
    destroyed() {
      console.log('root destroyed');
    }
  })

  // 创建时：先创建父组件，再创建子组件
  // 挂载时：先挂载子组件，再挂载父组件
  // patch的多次递归嵌套
</script>
</html>